<template>
  <div>
<h2>门店添加</h2>
  </div>
  <table border="1">
    <tr>
      <td>门店</td>
     
      <td>
        <select v-model="state.sid">
          <option value="">请选择</option>
          <option value="昌平南口">昌平南口</option>
          <option value="北京顺义">北京顺义</option>
          <option value="昌平南路口">昌平南路口</option>

        </select>
      </td>
    </tr>
    <tr>
      <td>优惠券标题</td>
      <td>
        <input type="text" v-model="state.name">
      </td>
    </tr>
    <tr>
    <td>库存数量</td>
    <td>
      <input type="text" v-model="state.num">
    </td>
   </tr>
   
    <tr>
      <td>优惠券类型</td>
      <td>
        <select v-model="state.type">
          <option value="">请选择</option>
          <option value="折扣券">折扣券</option>
          <option value="代金券">代金券</option>
          <option value="兑换券">兑换券</option>

        </select>
      </td>
    </tr>
    <tr>
      <td>优惠券颜色</td>
      <td>
        <input type="color" v-model="state.color">
      </td>
    </tr>
   
    <tr>
      <td></td>
      <td>
        <input type="button" value="添加" @click="add">
      </td>
    </tr>
  </table>
</template>

<script setup lang="ts">
import axios from 'axios';
import{reactive,toRefs,onMounted}from'vue'
import { useRoute,useRouter } from 'vue-router';
let router=useRouter();
let route=useRoute();
let data:any=reactive({
  state:{
  sid: '',
  name: '',
  num: '',
  type: '',
  color: '',
  },
 
  
})
let{state}=toRefs(data)
function add()
{
  let obj={
  "sid": state.value.sid,
  "name": state.value.name,
  "num": state.value.num,
  "type": state.value.type,
  "color": state.value.color,
  }
  // if(state.value.name=="")
  // {
  //   alert("优惠券名称不能为空")
  //   return;
  // }
  
  axios({
    url:'/api/DisCount/DisCountAdd',
    method:'post',
    data:obj
  })
  .then(res=>{
   if(res.data.data==1)
   {
    alert("添加成功")
   
   }
   else if(res.data.data==-1)
   {
    alert("优惠券名称不能重复")
    return;
   }
  })
  .catch(err=>{

  })
}

</script>

<style scoped>

</style>